home *** CD-ROM | disk | FTP | other *** search
- Path: boy.nmd.msu.ru!not-for-mail
- From: krotoff@such.srcc.msu.su (Alexander Krotoff)
- Newsgroups: comp.lang.c++
- Subject: a lady need help
- Date: 21 Jan 1996 22:24:38 +0300
- Organization: Research Computer Center, Moscow State University
- Sender: krotoff@boy.nmd.msu.ru
- Message-ID: <4du3tm$3cm@boy.nmd.msu.ru>
- References: <4drln1$f9i$1@mhadg.production.compuserve.com>
- NNTP-Posting-Host: boy.nmd.msu.ru
- X-Comment-To: linda siu <103051.3457@CompuServe.COM>
-
- linda siu <103051.3457@CompuServe.COM> wrote:
- > I lost my job and went for an interview lately.
- >
- > I am still confuse about some of the c++ question.
- >
- > Please help !
- >
- > a) What is a initialization list and when/how to use it.
-
- `initialization list' is not defined in the C++.
-
- It probably is `initializer list'. It is construction
- like following:
-
- struct A {
- int b;
- int c;
- };
-
- struct A aa[2] = { {1,2}, {3,4} };
- ^^^^^^^^^^^^^^^^^
- This list is called initializer list.
- It may be used to initialize any aggregate class
- (aggregate classes are very similar to C style
- structs and unions) and arrays.
-
- Probably it is `ctor initializer list' this is used
- in the constructor body to pass parameters to the base
- classes constructors and to initialize members of the
- class. In C++ initialization and assignments are
- distingushed.
- For example it is impossible to initialize member
- of reference type different way.
- Example:
-
- class B {
- public:
- int &a;
- B (int &p): a(b) {}
- // ^^^^
- };
-
- class D: public B {
- public:
- D (int &p): B(p) {}
- // ^^^^
- };
-
- In the first case we use ctor initializer to initialize
- class member. In the second case we used it to pass parameter
- to base class constructor.
-
- > b) what is the advantage of new/delete over malloc/free.
-
- There are a number of new faeatures. At first: malloc is
- not typed (it returns `void*' it is not siignifant in C,
- but significant in c++), but new "returns" typed pointer.
- new and delete operators knows about C++ costructors and
- destructors, but malloc do not.
-
- If you proogramming on the c++ you shell avoid to use
- malloc() and free() at least while you are not expert
- in this area ;-)
-
- Regards,
- --
- Alexander N. Krotoff krotoff@such.srcc.msu.su
- Research Computer Center tel: +7(095)939-2638
- Moscow State University fax: +7(095)939-4430
-
- ε╒ ╦┴╦ ┬┘╠╧ ╬┼ ╒┬╠┴╓╔╘╪ ─┴═╧▐╦╒...
-